from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time,unittest

class A3mall(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Edge()
        self.driver.get('http://10.59.9.12:7001/')
        self.driver.maximize_window()

    def tearDown(self):
        time.sleep(5)
        self.driver.quit()

    def test_A3mall_01_login(self):
        self.driver.find_element(By.XPATH,'//a[@href="/home/login.html"]').click()
        dy1 = self.driver.find_element(By.CLASS_NAME,'reg-new').text
        print(dy1)
        self.driver.find_element(By.NAME,'username').send_keys('18620064667')
        self.driver.find_element(By.NAME,'password').send_keys('123456')
        time.sleep(10)
        self.driver.find_element(By.CLASS_NAME,'finish-btn').click()
        time.sleep(5)
        dy2 = self.driver.find_element(By.XPATH,'/html/body/div[4]/a[2]').text
        print(dy2)
        dy3 = self.driver.find_element(By.XPATH,'/html/body/div[5]/div[2]/div[1]/div[2]/div[2]/ul/li[4]/span').text
        dy31 = dy3.replace('¥ ','')
        print(dy31)

    def test_A3mall_02_search(self):
        self.test_A3mall_01_login()
        self.driver.find_element(By.XPATH, '/html/body/div[3]/div[2]/ul/li[1]/a').click()
        sou = self.driver.find_element(By.XPATH, '//input[@class="search-input" and @name="keywords"]')
        sou.send_keys('非洲之心')
        sou.send_keys(Keys.ENTER)
        time.sleep(1)
        dy4 = self.driver.find_element(By.XPATH,'/html/body/div[4]/a[2]').text
        print(dy4)
        self.driver.find_element(By.XPATH,'//img[@src="/uploads/images/20250606/af9ef24936d60ea1dfe55120bccc1906.png"]').click()
        dy5 = self.driver.find_element(By.ID,'sell-price-box').text
        print(dy5)
        shu = self.driver.find_element(By.ID,'store_nums')
        shu.clear()
        shu.send_keys('2')
        dy6 = shu.text
        print(dy6)
        self.driver.find_element(By.ID,'buy-cart').click()
        dy7 = self.driver.find_element(By.XPATH,'/html/body/div[4]/div[2]/ul/li[2]/em').text
        print(dy7)
        self.driver.find_element(By.ID,'address-828').click()
        self.driver.find_element(By.XPATH,'//*[@id="order-button"]').click()
        time.sleep(1)
        dy8 = self.driver.find_element(By.XPATH,'/html/body/div[4]/div[3]/span').text
        print(dy8)
        self.driver.find_element(By.XPATH,'/html/body/div[4]/div[3]/p/a').click()
        dy9 = self.driver.find_element(By.XPATH,'/html/body/div[5]/div[2]/div/div[2]/table[2]/tbody/tr[2]/td[2]').text
        print(dy9)

if __name__ == '__main__':
    unittest.main()